﻿using ToolGood.Words;

namespace ContactSMS.Commons.Util
{
    public class PinyinHelper
    {
        public static (string Initials, string FullPinyin) GetInitialsAndFullPinyin(string input)
        {
            string initials = WordsHelper.GetFirstPinyin(input); // 获取首字母
            string fullPinyin = WordsHelper.GetPinyin(input);        // 获取全拼音

            // 对于非汉字，处理为字母或原字符
            string initialsProcessed = "";
            foreach (char c in input)
            {
                if (char.IsLetterOrDigit(c) && initialsProcessed.Length < initials.Length)
                {
                    initialsProcessed += initials[initialsProcessed.Length];
                }
                else if (!char.IsLetter(c))
                {
                    initialsProcessed += c; // 保留非字母字符
                }
            }

            return (initialsProcessed, fullPinyin);
        }

        public static string GetFirstCharToLower(string input)
        {
            if (string.IsNullOrEmpty(input))
            {
                return string.Empty; // 如果字符串为空，返回空字符串
            }

            char firstChar = input[0];            // 获取第一个字符
            char lowerFirstChar = char.ToLower(firstChar); // 转为小写

            return lowerFirstChar.ToString();
        }
    }
}
